#include "NetworkInfoCollection.h"

NetworkInfoCollection::NetworkInfoCollection(QObject *parent)
    : InfoCollectionBase(parent)
    , notVirtualNetworkCmd(QString("ls %1|grep -v \"$(ls %2)\"").arg(s_networkPath,s_virtualNetworkPath))
{

}

QString NetworkInfoCollection::getNetworkType()
{
    QList<QString> networkList;
    QList<QString> returnNetworkTypeList;
    getPopenResult(notVirtualNetworkCmd,networkList);
    foreach (QString tempNetworkPath, networkList) {
        QFileInfo tempFileInfo(QString("%1/%2/%3").arg(s_networkPath,tempNetworkPath,s_wirelessKey));
        if (tempFileInfo.exists() && tempFileInfo.isDir()) {
            returnNetworkTypeList.append(QString(s_wirelessInterfaceKey));
        } else {
            returnNetworkTypeList.append(QString(s_ethernetInterfaceKey));
        }
    }
    return returnNetworkTypeList.join(s_separator);
}

QString NetworkInfoCollection::getNetworkMac()
{
    QList<QString> networkList;
    QList<QString> returnNetworkTypeList;
    getPopenResult(notVirtualNetworkCmd,networkList);
    foreach (QString tempNetworkPath, networkList) {
        QString tempStr;
        getOnePopenResult(QString("cat %1/%2/%3").arg(s_networkPath,tempNetworkPath,s_addressKey),tempStr);
        returnNetworkTypeList.append(tempStr);
    }
    return returnNetworkTypeList.join(s_separator);
}
